import { defineStore } from 'pinia'
import { AppState } from './types';
import defaultSettings from '@src/config/setting.json'

const useAppStore = defineStore('app', {
    state: (): AppState => ({ ...defaultSettings }),
    getters: {
        appCurrentSetting(state: AppState): AppState {
            return { ...state }
        }
    },
    actions: {
        updateSettings(partial: Partial<AppState>) {
            this.$patch(partial)
        },
        toggleTheme(dark: boolean) {
            if (dark) {
                this.theme = 'dark';
                document.body.setAttribute('arco-theme', 'dark')
            } else {
                this.theme = 'light';
                document.body.removeAttribute('arco-theme')
            }
        }
    },
    persist: {
        key: 'appStore',
        paths: ['menuCollapse']
    }
})

export default useAppStore
